/*
 * Creative Bulletin Board Generation 3
 * Version 1.0 Beta 1
 +------------------------------------
 * CBB Registration form JS
 * Started: Oct 16, 2009 9:16 PM
 +------------------------------------
 */

//------------------------------------
// Define global variables.
var submit = $("#submitbutton");
var login = $("#loginname");
var display = $("#displayname");
var pass = $("#password");
var pass2 = $("#password2");
var email = $("#email");
var email2 = $("#email2");

//------------------------------------
// Check-it-up
function validateLoginName(){
	if(login.val().length < 3){
		login.addClass("error");
		display.removeClass("ok");
	}
	else{
		login.removeClass("error");
		login.addClass("ok");
	}
}

function validateDisplayName(){
	if(display.val().length < 4){
		display.addClass("error");
		display.removeClass("ok");
	}
	else{
		display.removeClass("error");
		display.addClass("ok");
	}
}

function validatePassword(){
	if(pass.val().length < 4){
		pass.addClass("error"); 
		pass.removeClass("ok");
	}
	else{
		pass.removeClass("error");
		pass.addClass("ok");
	}
}

function validateConfirmPassword(){
	if(pass2.val() != pass.val()){
		pass2.addClass("error");
		pass2.removeClass("ok");
	}
	else{
		pass2.removeClass("error");
		pass2.addClass("ok");
	}
}

function validateEmail(){
	if(email.val().match(/([a-z0-9._-]+@[a-z0-9._-]+.[a-z]+)/gi) == null){
		email.addClass("error"); 
		email.removeClass("ok");
	}
	else{
		email.removeClass("error");
		email.addClass("ok");
	}
}

function validateConfirmEmail(){
	if(email.val() != email2.val()){
		email2.addClass("error");
		email2.removeClass("ok");
	}
	else{
		email2.removeClass("error");
		email2.addClass("ok");
	}
}



login.blur(validateLoginName);
display.blur(validateDisplayName);
pass.blur(validatePassword);
pass2.blur(validateConfirmPassword);
email.blur(validateEmail);
email2.blur(validateConfirmEmail);

login.keyup(validateLoginName);
display.keyup(validateDisplayName);
pass.keyup(validatePassword);
pass2.keyup(validateConfirmPassword);
email.keyup(validateEmail);
email2.keyup(validateConfirmEmail);
